package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.riding.OrderBean;
import com.lzm.ydpt.module.riding.fragment.RidingHomeFragment;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.HomeContract;
import com.lzm.ydpt.mvp.modelimpl.HomeModelImpl;

import java.util.List;


/**
 * 类名称：HomePresenterImpl
 * 类描述：代理实现
 */
public class HomePresenterImpl extends BasePresenter implements HomeContract.Presenter {

    private HomeContract.View mView;
    private HomeContract.Model mModel;

    public HomePresenterImpl(RidingHomeFragment context) {
        super(context.getActivity());
        this.mView = context;
        this.mModel = new HomeModelImpl();
    }

    @Override
    public void onOrderList(FormBodys formBodys) {
        mManager.http(mModel.onOrderList(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<List<OrderBean>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<List<OrderBean>> entity) {
                mView.onOrderList(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onOrderList"));
    }

    @Override
    public void onEdtState(FormBodys formBodys,int receiveStatus) {
        mManager.http(mModel.onEdtState(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Integer>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Integer> entity) {
                mView.onEdtState(entity.getMessage(),receiveStatus);
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onEdtState"));
    }

}